home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / getopt.exe / TESTOPT.PAS < prev   
Pascal/Delphi Source File  |  1993-04-08  |  1KB  |  60 lines

  1. PROGRAM TESTOPT_;
  2. {Test GETOPT_.PAS and GETOTP2_.PAS}
  3. {$DEFINE OPT2}
  4. {$IFNDEF OPT2}
  5. USES GETOPT_;
  6. const
  7.   optionS : pChar = 'A:F:PuU:wXZ:';
  8. {$ELSE}
  9. USES GETOPT2_;
  10. const
  11.   optionS : pChar = 'AFUZ';
  12. {$ENDIF}
  13. var
  14.   ch :Char;
  15.    i :Integer;
  16. begin
  17.   i := 0;
  18.   writeln;
  19.   writeln('----');
  20.   repeat
  21.     ch := getOpt(optionS);
  22.     if ch <> EOFch
  23.     then begin
  24.       inc(i);
  25.       write('***** Item ',i:2, ' is ');
  26.       if ch = NONOPTch
  27.       then
  28.         write('NON SWITCH')
  29.       else if ch = ERRORch
  30.       then
  31.         write('ERROR     ')
  32.       else
  33.         write('SWITCH   ',ch);
  34.       if optArg <> nil
  35.       then
  36.         write(': ',optarg);
  37.       writeln
  38.     end;
  39.     { the following CASE statement is what you would do in your
  40.       program}
  41.     case ch of
  42.       'A', 'F', 'U', 'Z':
  43.           writeln(optArg, ' is a nice argument for switch ',ch);
  44.       'P','w','X':
  45.           writeln(ch, ' is a lonesome switch');
  46.       'u','U':
  47.           writeln('U and u are the same to me');
  48.       NONOPTch:
  49.           writeln('I''m ignoring non-switches like ', optarg);
  50.       ERRORch:
  51.           writeln('That''s a buggy command-line');
  52.       else
  53.           writeln('no comments about switches I don''t know');
  54.     end;
  55.   until (ch = EOFch);
  56.   writeln;
  57.   for i := 1 to argc
  58.   do
  59.     writeln('argv[', i,'] is  ',argv[i])
  60. end.